﻿<%@ Page StylesheetTheme="Skin1" Language="C#" MasterPageFile="~/LTR/MlyLtrMaster.Master"
  AutoEventWireup="true" EnableEventValidation="false" CodeBehind="gridBasePage.aspx.cs"
  Inherits="MLY.LTR.gridBasePage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="titleHolder" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

  <script type="text/javascript">
        
        function tSplitValue(txt) {
            $("#<%= splitHidden.ClientID %>").val(txt.value);

        }
        
        function openDialog(distId, quantity, planned, actual, original) {
            if (original) {
                $("#<%= distActualDateTxt.ClientID %>").val(actual);
                $("#<%= sentQuantToEditTxt.ClientID %>").val(quantity);
                $("#<%= distPlannedDateTxt.ClientID %>").val(planned);
                $("#<%= hiddenDistToEdit.ClientID %>").val(distId);

                $("#dialog").toggle();
            }
        }

        function showDistEditLink(originalWoId) {
            alert('FFF');
            return (originalWoId != null);
        }
        
        function hideDistEditLink(originalWoId) {
            return (originalWoId == null);
        }

  </script>

  <asp:HiddenField runat="server" ID="splitHidden" />
  <div class="filterDiv">
    <table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td>
          <asp:Literal runat="server" ID="orgNameLit" Text='<%$ Dict:InventoryGrid.addFilter %>' />
        </td>
        <td style="padding-left: 10px;" id="win-xp">
          <asp:DropDownList CssClass="filterDdl" runat="server" AutoPostBack="true" ID="ddlColumnList"
            OnSelectedIndexChanged="columnListDdl_SelectedIndexChanged" AppendDataBoundItems="true">
            <asp:ListItem Selected="True" Text="<%$ Dict:InventoryGrid.ChooseColumnToFilter %>"
              Value="0"></asp:ListItem>
          </asp:DropDownList>
        </td>
        <td style="width: 240px; padding-left: 10px;">
          <asp:Button ID="Button1" CssClass="Btn smallBtn" runat="server" Text="<%$ Dict:InventoryGrid.SubmitFilter %>"
            OnClick="Unnamed1_Click" />&nbsp;
          <img src="../Images/line_devision-between-buttun.png" style="vertical-align: bottom;" />&nbsp;
          <asp:Button ID="Button2" runat="server" CssClass="Btn smallBtn" Text="<%$ Dict:InventoryGrid.ClearFilter %>"
            OnClick="ClearClick" />
        </td>
      </tr>
      <tr>
        <td>
          <asp:Literal runat="server" ID="Literal1" Text='<%$ Dict:InventoryGrid.CalcField %>' />
        </td>
        <td style="padding-left: 10px;">
          <asp:DropDownList runat="server" AutoPostBack="true" ID="ddlCalcField" OnSelectedIndexChanged="ddlCalcField_SelectedIndexChanged"
            AppendDataBoundItems="true">
            <asp:ListItem Selected="True" Value="PlannedDate" Text="<%$ Dict:WorkOrderColumn.PlannedDate %>"></asp:ListItem>
            <asp:ListItem Selected="False" Value="RequestedDeliveryDate" Text="<%$ Dict:WorkOrderColumn.RequestedDelivery %>"></asp:ListItem>
          </asp:DropDownList>
        </td>
        <td style="width: 240px; padding-left: 10px;">
        </td>
      </tr>
      <tr>
        <td colspan="3" style="padding-left: 10px; height: 30px; padding-top: 15px;">
          <% if (GridView1.Rows.Count == 0)
             { %>
          <asp:HyperLink ID="HyperLinkAddNew" runat="server" Text="<%$ Dict:InventoryGrid.AddNewWo %>"
            NavigateUrl='<%# isClient == false ? "~/LTR/ContractoraddWoFrm.aspx" :
                                        "~/LTR/ClientaddWoFrm.aspx" %>'>

          </asp:HyperLink>
          <% } %>
          <% if (GridView1.Rows.Count > 0)
             { %>
          <asp:Button runat="server" Text='<%$Dict:clientAddWo.CancelSorting%>' ID="cancelSort"
            OnClick="cancelSort_Click" CssClass="Btn largeBtn floater" Style="text-align: center;" />
          <%} %>
        </td>
      </tr>
    </table>
    <asp:Label ID="ErrLbl" ForeColor="Red" Font-Bold="true" runat="server"></asp:Label>
  </div>
  <table border="0" cellpadding="0" cellspacing="0" class="sortPlaceHolder floater">
    <tr>
      <asp:PlaceHolder runat="server" EnableViewState="true" ID="advancedSortPanel"></asp:PlaceHolder>
    </tr>
  </table>
  <br clear="all" />
  <div style="display: none;" id="dialog" title="Edit Distribution">
    <asp:HiddenField runat="server" ID="hiddenDistToEdit" />
    <table cellpadding="0" cellspacing="0" style="width: 100%;" border="0">
      <tr>
        <td style="width: 200px;">
          <asp:Label runat="server" Text="<%$ Dict:InventoryGrid.distEditQuantity %>"></asp:Label>
        </td>
        <td>
          <asp:TextBox runat="server" ID="sentQuantToEditTxt"></asp:TextBox>
        </td>
      </tr>
      <tr>
        <td>
          <asp:Label ID="Label2" runat="server" Text="<%$ Dict:InventoryGrid.distPlannedDate %>"></asp:Label>
        </td>
        <td>
          <asp:TextBox runat="server" ID="distPlannedDateTxt"></asp:TextBox>
          <KBMControls:KbmCalendar TargetControlID="distPlannedDateTxt" runat="server" ID="KbmCalendar2">
          </KBMControls:KbmCalendar>
        </td>
      </tr>
      <tr>
        <td>
          <asp:Label ID="Label4" runat="server" Text="<%$ Dict:InventoryGrid.distActualDAte %>"></asp:Label>
        </td>
        <td>
          <asp:TextBox runat="server" ID="distActualDateTxt"></asp:TextBox>
          <KBMControls:KbmCalendar TargetControlID="distActualDateTxt" runat="server" ID="KbmCalendar1">
          </KBMControls:KbmCalendar>
        </td>
      </tr>
      <tr>
        <td>
          <asp:Button runat="server" Text="<%$ Dict:InventoryGrid.EditDist %>" ID="editDistBtn" />
        </td>
        <td>
          <a onclick="javascript:openDialog(2)" href="javascript:void(0)">
            <asp:Label ID="Label3" runat="server" Text="<%$ Dict:InventoryGrid.closeEditDist %>"></asp:Label>
          </a>
        </td>
      </tr>
      <tr>
        <td colspan="2">
        </td>
      </tr>
    </table>
  </div>
  <asp:GridView ID="GridView1" SkinID="GridViewSkin" runat="server" AutoGenerateColumns="False"
    CssClass="invGrid" HeaderStyle-CssClass="headerClass" DataKeyNames="WorkOrderId,ContractorId"
    DataSourceID="LinqDataSource1" AllowPaging="True" PageSize='<%# Session["DefaultLinesinGrid"] != null ?  int.Parse(Session["DefaultLinesinGrid"].ToString()) : int.Parse(MLY.Utils.getAppConfigString("DefaultRowsInGrid")) %>'
    OnRowDataBound="GridView1_RowDataBound" AllowSorting="true" OnPageIndexChanged="GridView1_PageIndexChanged"
    OnSorting="GridView1_Sorting" CellSpacing="0" OnPageIndexChanging="GridView1_PageIndexChanging"
    OnRowCommand="GridView1_RowCommand">
    <Columns>
      <asp:TemplateField ControlStyle-Width="20">
        <HeaderTemplate>
          <asp:Label runat="server" Text='<%$ Dict:InventoryGrid.addWoBtn %>'></asp:Label><br />
          <asp:ImageButton ID="HyperLinkAddNew" ImageUrl="/Images/add_line_icon.png" PostBackUrl='<%# isClient == false ? "~/LTR/ContractoraddWoFrm.aspx":
"~/LTR/ClientaddWoFrm.aspx" %>' runat="server" />
        </HeaderTemplate>
        <ItemTemplate>
          <asp:HyperLink ID="HyperLinkOpen" runat="server" NavigateUrl='<%# isClient == false ?
                String.Format(&quot;ContractoreditWoForm.aspx?Edit={0}&quot;,Eval(&quot;WorkOrderId&quot;)) :
                String.Format(&quot;ClienteditWoForm.aspx?Edit={0}&quot;,Eval(&quot;WorkOrderId&quot;))
                %>'>
            <asp:Image ID="imgOpen" runat="server" ImageUrl="~/Images/Magnify_icon.png" />
          </asp:HyperLink>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderStyle-Width="40">
        <HeaderTemplate>
          <asp:HyperLink ID="HyperLinkSplit" runat="server">
            <asp:Image ID="imgAddNewSplit" runat="server" ImageUrl="~/Images/split_icon.png" />
          </asp:HyperLink>
        </HeaderTemplate>
        <ItemTemplate>
          <asp:MultiView runat="server" ActiveViewIndex='<%# SplitOrderNum.ToString() == Eval("workOrderId") ? 1 : 0 %>'
            ID="splitMultiView">
            <asp:View runat="server" ID="mySecondView">
              <asp:ImageButton runat="server" ID="splitImg" CommandArgument='<%# Eval("workOrderId") %>'
                OnClick="SplitImageButtonClicked" ImageUrl="~/Images/split_icon.png" />
            </asp:View>
            <asp:View runat="server" ID="myView">
              <asp:ImageButton runat="server" ImageUrl="~/Images/close_icon.png" OnClick="CancelSplitClicked"
                CausesValidation="false" />
              <br />
              <asp:TextBox Width="37" CssClass="blueBorder" Style="font-size: 9px; font-weight: bold;
                color: #17a3d0" runat="server" onchange="tSplitValue(this)" ID="howMuchToSplitTxt"></asp:TextBox>
              <asp:LinkButton ID="Button1" OnClick="splitSubmit_Click" CommandArgument='<%# Eval("workOrderId") %>'
                runat="server" Text="submit" CausesValidation="true" Style="font-size: 10px; font-weight: bold;
                color: #17a3d0"></asp:LinkButton>
            </asp:View>
          </asp:MultiView>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderStyle-Width="64" HeaderText="<%$ Dict:InventoryGrid.org_NameColumn %>"
        SortExpression="">
        <HeaderTemplate>
          <asp:LinkButton Text="<%$ Dict:InventoryGrid.org_NameColumn %>" ID="header" ForeColor="White"
            CommandName="Sort" CommandArgument='<%# isClient == true ? "tableOrganization1.OrganizationName" : "tableOrganization.OrganizationName" %>'
            runat="server">
          </asp:LinkButton>
        </HeaderTemplate>
        <ItemTemplate>
          <table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td style="width: 10px;">
                <uc:StyledCheckBox AutoPostBack="false" runat="server" />
              </td>
              <td>
                <asp:Label runat="server" Text='<%# isClient == true ? Eval("tableOrganization1.OrganizationName") : Eval("tableOrganization.OrganizationName") %>'></asp:Label>
              </td>
              <% if (MLY.Bll.clsUser.CurrentUserRoleId == (int)MLY.Bll.clsUser.enumRoleId.Role60_Admin)
                 { %>
              <td>
                <asp:ImageButton ID="delWoBtn" runat="server" ImageUrl="~/Images/Cancel.gif" Width="10"
                  CommandArgument='<%# Eval("WorkOrderId") %>' OnClick="delWoBtn_Click" Style="height: 10px" />
                <ajaxToolKit:ConfirmButtonExtender TargetControlID="delWoBtn" ConfirmText="<%$ Dict:InventoryGrid.ConfirmDelete %>"
                  runat="server">
                </ajaxToolKit:ConfirmButtonExtender>
              </td>
              <%} %>
            </tr>
          </table>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:BoundField DataField="CustomerWorkOrderNumber" ControlStyle-Width="52" HeaderText="<%$ Dict:InventoryGrid.Cust_WO_NumColumn %>"
        SortExpression="CustomerWorkOrderNumber" />
      <asp:BoundField DataField="ContractorWorkOrderNumber" ControlStyle-Width="56" HeaderText="<%$ Dict:InventoryGrid.Contractor_WO_NumColumn %>"
        SortExpression="ContractorWorkOrderNumber" />
      <asp:TemplateField HeaderText="<%$ Dict:InventoryGrid.SendDateColumn %>" ControlStyle-Width="33"
        SortExpression="SendDate">
        <HeaderTemplate>
          <asp:LinkButton Text="<%$ Dict:InventoryGrid.SendDateColumn %>" ID="header1" ForeColor="White"
            CommandName="Sort" CommandArgument="SendDate" runat="server">
          </asp:LinkButton>
        </HeaderTemplate>
        <ItemTemplate>
          <asp:Label runat="server" Width="120" Text='<%# Eval("SendDate","{0:dd-MM-yyyy}") %>'></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField ItemStyle-Wrap="false">
        <HeaderTemplate>
          <asp:LinkButton CssClass="innerSpan" Text="<%$ Dict:InventoryGrid.PlannedDelivaryColumn %>"
            ID="LinkButton1" ForeColor="White" CommandName="Sort" CommandArgument="PlannedDelivaryDate"
            runat="server"> </asp:LinkButton>
          &nbsp; |
          <asp:LinkButton CssClass="innerSpan" Text="<%$ Dict:InventoryGrid.ActualDelivaryDateColumn %>"
            ID="header2" ForeColor="White" CommandName="Sort" CommandArgument="ActualDelivaryDate"
            runat="server">

          </asp:LinkButton>&nbsp;|
          <asp:LinkButton CssClass="innerSpan" Text="<%$ Dict:InventoryGrid.QuantitySentColumn %>"
            ID="LinkButton2" ForeColor="White" CommandName="Sort" CommandArgument="Quantity"
            runat="server">
          </asp:LinkButton>
        </HeaderTemplate>
        <ItemTemplate>
          <asp:Repeater runat="server">
            <ItemTemplate>
              <div>
                <span class="innerSpan">&nbsp;<%# Eval("PlannedDelivaryDate") == null ? @"-/-" : Eval("PlannedDelivaryDate", "{0:dd-MM-yy}")%></span>
                | <span class="innerSpan">&nbsp;<%# Eval("ActualDelivaryDate") == null ? @"-/-" : Eval("ActualDelivaryDate", "{0:dd-MM-yy}")%>
                </span>| <span class="innerSpan"><span condition="false">&nbsp; <a style="color: inherit;
                  text-decoration: underline;" href="javascript:void(0);" onclick="javascript:openDialog(<%# Eval("WorkOrderId") %>
                                ,'<%# Eval("Quantity") %>' 
                                , '<%# Eval("PlannedDelivaryDate") %>' 
                                ,'<%# Eval("ActualDelivaryDate") %>','<%# Eval("originalWoForDist") %>' )"
                  visible="javascript:showDistEditLink('<%# Eval("originalWoForDist") %>');">
                  <%# Eval("originalWoForDist") != null || Eval("ActualDelivaryDate") != null?(Eval("Quantity") == null ? @"-/-" : Eval("Quantity")) : 0m %></a></span></span>
              </div>
            </ItemTemplate>
          </asp:Repeater>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="<%$ Dict:InventoryGrid.OpenBalanceColumn %>">
        <ItemTemplate>
          <asp:Label ID="Label1" runat="server" Text='<%#
                     GetInventoryBalance((int)Eval("WorkOrderId") )
                      %>'></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="<%$ Dict:InventoryGrid.OpenQuantityColumn %>">
        <ItemTemplate>
          <asp:Label ID="Label5" runat="server" Text='<%#  MLY.Bll.clsWorkOrder.GetOpenQuantity(Eval("WorkOrderId")) %>'></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:BoundField DataField="Quantity" ControlStyle-Width="40" HeaderText="<%$ Dict:InventoryGrid.QuantityColumn %>"
        SortExpression="Quantity" />
      <asp:BoundField DataField="originalQuantity" ControlStyle-Width="40" HeaderText="<%$ Dict:InventoryGrid.originalQuantity %>"
        SortExpression="originalQuantity" />
      <asp:BoundField DataField="RequestedDelivaryDate" DataFormatString="{0:dd-MM-yy}"
        ControlStyle-Width="40" HeaderText="<%$ Dict:InventoryGrid.RequestedDelivaryColumn %>"
        SortExpression="RequestedDelivaryDate" />
      <asp:BoundField DataField="CustomerPriority" ControlStyle-Width="40" HeaderText="<%$ Dict:InventoryGrid.PriorityColumn %>"
        SortExpression="CustomerPriority" />
      <asp:BoundField DataField="CustomerCatalougeCode" ControlStyle-Width="50" HeaderText="<%$ Dict:InventoryGrid.CustCatalougeCodeColumn %>"
        SortExpression="CustomerCatalougeCode" />
      <asp:BoundField DataField="ContractorCatalogueCode" ControlStyle-Width="57" HeaderText="<%$ Dict:InventoryGrid.ContrCatalogueCodeColumn %>"
        SortExpression="ContractorCatalogueCode" />
      <asp:BoundField DataField="ProductDescription" ControlStyle-Width="60" HeaderText="<%$ Dict:InventoryGrid.ProductDescriptionColumn %>"
        SortExpression="ProductDescription" />
      <asp:BoundField DataField="TextFieldA" ControlStyle-Width="40" HeaderText="<%$ Dict:InventoryGrid.TextAColumn %>"
        SortExpression="TextFieldA" />
      <asp:BoundField DataField="Remarks" ControlStyle-Width="78" HeaderText="<%$ Dict:InventoryGrid.RemarksColumn %>"
        SortExpression="Remarks" />
      <asp:BoundField DataField="OrderNumber" ControlStyle-Width="42" HeaderText="<%$ Dict:InventoryGrid.OrderNumberColumn %>"
        SortExpression="OrderNumber" />
      <asp:BoundField DataField="SplitId" HeaderText="<%$ Dict:InventoryGrid.SplitIdColumn %>"
        SortExpression="SplitId" ControlStyle-Width="26" />
    </Columns>
  </asp:GridView>
  <asp:LinqDataSource ID="LinqDataSource1" runat="server" EnableDelete="true" ContextTypeName="MLY.Dal.lqKbmDataContext"
    TableName="TableWorkOrders" OnDeleting="LinqDataSource1_Deleting">
  </asp:LinqDataSource>
  <asp:ObjectDataSource runat="server" SortParameterName="sortDirection" ID="dynamicWhereObjectSource"
    SelectMethod="getDataFromWhere" EnableViewState="false" TypeName="MLY.Bll.clsWorkOrder"
    EnableCaching="false">
    <SelectParameters>
      <asp:SessionParameter DefaultValue="&quot;&quot;" Name="where" SessionField="whereClause"
        Type="String" />
    </SelectParameters>
  </asp:ObjectDataSource>
</asp:Content>
